package com.bupt.liutong.admin.sch.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.bupt.liutong.admin.core.base.BaseAction;
import com.bupt.liutong.admin.sch.bo.AlbumBo;
import com.bupt.liutong.admin.sch.form.AlbumForm;
import com.bupt.liutong.util.BeanUtils;

public class AlbumAction extends BaseAction {

	private AlbumBo albumBo;

	public ActionForward getAlbumsByPage(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		AlbumForm albumForm = (AlbumForm) form;
		// request.setAttribute("ctmMap", ctm.get("?"));
		request.setAttribute("albumFormList", albumBo.getAlbumsByPage(
				albumForm, request));
		putPageInfo(request, albumForm);
		return mapping.findForward("getAlbumsByPageSuccess");
	}

	public ActionForward insertAlbum(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// request.setAttribute("?List", getOptionList(ctm.get("?"), false));
		return mapping.findForward("insertAlbumSuccess");
	}

	public ActionForward insertAlbumDo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		AlbumForm albumForm = (AlbumForm) form;
		albumBo.insertAlbum(albumForm);
		return mapping.findForward("insertAlbumDoSuccess");
	}

	public ActionForward updateAlbum(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		// request.setAttribute("?List", getOptionList(ctm.get("?"), false));
		AlbumForm albumForm = (AlbumForm) form;
		BeanUtils.copyProperties(albumForm, albumBo.getAlbumById(albumForm));
		return mapping.findForward("updateAlbumSuccess");
	}

	public ActionForward updateAlbumDo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		AlbumForm albumForm = (AlbumForm) form;
		albumBo.updateAlbum(albumForm);
		return mapping.findForward("updateAlbumDoSuccess");
	}
	
	public ActionForward updateAlbumCover(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("albumId");
		String coverId = request.getParameter("coverId");
		albumBo.updateAlbumCover(Integer.valueOf(id), Integer.valueOf(coverId));
		return mapping.findForward("updateAlbumCoverSuccess");
	}

	public ActionForward deleteAlbums(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String[] ids = request.getParameterValues("id");
		albumBo.deleteAlbums(ids);
		return mapping.findForward("deleteAlbumsSuccess");
	}

	public void setAlbumBo(AlbumBo albumBo) {
		this.albumBo = albumBo;
	}
}
